FROM php:8.2.9-fpm-alpine

# 安装 nginx 和扩展
#RUN apk add --no-cache nginx supervisor bash \
#    && docker-php-ext-install pdo pdo_mysql

# 使用国内源，安装必要包（含 PHP 扩展的系统依赖），并清理缓存
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
    apk update && apk add --no-cache \
        nginx \
        supervisor \
        bash \
        libzip-dev \
        && docker-php-ext-install pdo pdo_mysql zip


# 设置工作目录
WORKDIR /var/www/html/quick_curd

# 复制项目代码
COPY ./src /var/www/html/quick_curd

# 复制 nginx 配置
COPY ./docker/nginx.conf /etc/nginx/nginx.conf
COPY ./docker/default.conf /etc/nginx/conf.d/default.conf

RUN find /var/www/html/quick_curd -type f -exec sed -i 's/\r$//' {} +

# 配置权限
RUN chown -R www-data:www-data /var/www/html/quick_curd


# 拷贝启动脚本
COPY ./docker/entrypoint.sh /usr/local/bin/entrypoint.sh
# 设置脚本权限
RUN sed -i 's/\r$//' /usr/local/bin/entrypoint.sh && chmod +x /usr/local/bin/entrypoint.sh


# 暴露 nginx 端口
EXPOSE 80

# 启动命令
ENTRYPOINT ["bash", "/usr/local/bin/entrypoint.sh"]

# 启动 nginx + php-fpm
#CMD ["sh", "-c", "php-fpm && nginx -g 'daemon off;'"]
